package cn.lili.modules.urbansubstation.entity.dto;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.security.enums.SceneEnums;
import cn.lili.modules.store.entity.enums.StoreStatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 城市分站搜索参数
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UrbanSubstationSearchParams implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "城市分站id集合")
    private List<String> urbanIds;

    @ApiModelProperty(value = "城市分站名称")
    private String urbanName;

    @ApiModelProperty(value = "城市分站状态")
    private String status;

    @ApiModelProperty(value = "开始时间")
    private String startDate;

    @ApiModelProperty(value = "结束时间")
    private String endDate;

    @ApiModelProperty(value = "城市分站所属城市ID")
    private String areaId;

    @ApiModelProperty(value = "场景", hidden = true)
    private String scene;

    @ApiModelProperty(value = "管理账号")
    private String username;

    @ApiModelProperty(value = "城市集合")
    private List<String> regionList;
    @ApiModelProperty(value = "省份ID")
    private String provinceId;
    @ApiModelProperty(value = "省份名称")
    private String provinceName;

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("lus.delete_flag",0);

        if (CollUtil.isNotEmpty(urbanIds)) {
            queryWrapper.in("lus.id", urbanIds);
        }
        if (CharSequenceUtil.isNotEmpty(urbanName)) {
            queryWrapper.like("lus.urban_name", urbanName);
        }
        if (CharSequenceUtil.isNotEmpty(status)) {
            queryWrapper.eq("lus.status", status);
        }
        //按时间查询
        if (CharSequenceUtil.isNotEmpty(startDate)) {
            queryWrapper.ge("lus.create_time", DateUtil.parse(startDate));
        }
        if (CharSequenceUtil.isNotEmpty(endDate)) {
            queryWrapper.le("lus.create_time", DateUtil.parse(endDate));
        }
        if (CharSequenceUtil.isNotEmpty(areaId)) {
            queryWrapper.eq("lus.user_id", areaId);
        }
        if (CharSequenceUtil.isNotEmpty(scene)) {
            queryWrapper.eq("lus.scene", SceneEnums.getScene(scene).name());
        }
        if (CharSequenceUtil.isNotEmpty(username)) {
            queryWrapper.like("lu.username", username);
        }
        return queryWrapper;
    }
}
